#coding:utf-8

'''
作为最经典的深度学习数据集，MNISIT包含65,000个灰度书写数字图片，
尺寸均为28x28，其中55,000个用于训练，10,000个用于测试 所有图片已归一化与中心化，像素值从0到1
'''

from tensorflow.examples.tutorials.mnist import input_data
import matplotlib.pyplot as plt
import numpy as np



#自动下载并导入数据
mnist=input_data.read_data_sets('./datas/mnist/',one_hot=True)

#load data
x_train=mnist.train.images
y_train=mnist.train.labels

x_test=mnist.test.images
y_test=mnist.test.labels

print('x_train:',x_train.shape)
print('y_train:',y_train.shape)
print('x_test:',x_test.shape)
print('y_test:',y_test.shape)

def pol_mnist(data,classes):
    for i in range(10):
        idxs=(classes==i)

        #get 10 images for class i
        images=data[idxs][:10]
        for j in range(5):
            plt.subplot(5,10,i+j*10+1)
            plt.imshow(images[j].reshape(28,28),cmap='gray')
            #print title only once for each class
            if j==0:
                plt.title(i)
            plt.axis('off')
    plt.show()

classes=np.argmax(y_train,1)
pol_mnist(x_train,classes)